package pl.edu.pw.polygen.ui.file;

import java.io.File;
import java.util.Observer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import pl.edu.pw.polygen.modeler.server.EditorServer;
import pl.edu.pw.polygen.util.ApplicationHelper;

import com.vaadin.ui.Panel;

@Component("editorPanelFactory")
public class EditorPanelFactory {
	
	@Autowired
	private Observer saveCommand;
	
	public Panel getPanel(){
		Panel panel = new Panel();
		panel.setWidth("100%");
		panel.setHeight("100%");
		panel.addComponent(getNewEditor());
		return panel;
	}
	
	private EditorServer getNewEditor() {
		EditorServer editorServer = new EditorServer();
		editorServer.addObserver(saveCommand);
		editorServer.setSizeFull();
		int height = getHeight();
		int width = getWidth();
		editorServer.setNewSize(width, height);
		return editorServer;
	}
	
	private int getWidth(){
		int width = (int) ApplicationHelper.getCurrentApplication()
		.getMainWindow().getWidth();
		int newWidth =  (int) (width - width*0.25 - 70 - 160);
		return newWidth;
	}
	
	private int getHeight(){
		int height = (int) ApplicationHelper.getCurrentApplication()
		.getMainWindow().getHeight();
		int newHeight = (int)(height - 23 - 32 - 44 );
		return newHeight;
	}

}
